package org.mbds.android.sismapp.activity;

import org.mbds.android.p2p.services.P2pService;
import org.mbds.android.sismapp.SismappApplication;
import org.mbds.android.sismapp.SismappMenu;
import org.mbds.android.sismapp.R;
import org.mbds.android.sismapp.SismappMessage;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

public class P2pActivity extends Activity {

	P2pService service;
	Intent mServiceIntent;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_p2p);
		//findViewById(R.id.button1).setEnabled(false);
	}
	

	@Override
	protected void onStart() {
		super.onStart();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}
	
	@Override
	protected void onDestroy(){
		//stopService(mServiceIntent);
		super.onDestroy();
	}

	/***********************/
	/* Create options menu */
	/***********************/
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		SismappMenu.onCreateOptionsMenu(this, menu);
		return super.onCreateOptionsMenu(menu);
	}

	/************************/
	/* Prepare options menu */
	/************************/
	@Override
	public boolean onPrepareOptionsMenu(Menu menu) {
		SismappMenu.onPrepareOptionsMenu(this, menu);
		return super.onPrepareOptionsMenu(menu);
	}

	/*******************************/
	/* Manage menu item selection */
	/*******************************/
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		SismappMenu.onOptionsItemSelected(this, item);
		return super.onOptionsItemSelected(item);
	}

	public void stopService(View view) {
		
		if(mServiceIntent != null)
			stopService(mServiceIntent);
		
		findViewById(R.id.button2).setEnabled(true);
		findViewById(R.id.button1).setEnabled(false);
	}

	public void startService(View view) {
		service = new P2pService();
	    mServiceIntent = new Intent(this, service.getClass());
		startService(mServiceIntent);
		//SismappApplication.getInstance().bindP2pService();
		findViewById(R.id.button2).setEnabled(false);
		findViewById(R.id.button1).setEnabled(true);
		
	}

}
